package com.cn.mobileproject.activity.fragment;

import android.annotation.SuppressLint;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;
import android.widget.Toast;

import com.cn.mobileproject.R;
import com.cn.mobileproject.data.GlobalValue;
import com.cn.mobileproject.data.SystemParams;
import com.cn.mobileproject.manager.TaskManager;
import com.cn.mobileproject.view.adapter.MyTaskAdapter;
import com.net.http.HttpException;

@SuppressLint("ValidFragment")
public class PublisTaskFragment extends TaskFragment {
	

	public PublisTaskFragment() {
		super();
	}
	
	public PublisTaskFragment(boolean check) {
		super(check);
	}

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		return super.onCreateView(inflater, container, savedInstanceState);
	}

	protected void initComponent() {
		super.initComponent();
		adapter.setList(GlobalValue.getInstance().getPublisInstructs());
		adapter.notifyDataSetChanged();
		type =1;
	}

	protected void initEvent() {
		super.initEvent();
	}

	@Override
	public void initInstructData() {
		super.initInstructData();
		if (GlobalValue.getInstance().getPublisInstructs() != null)
			GlobalValue.getInstance().getPublisInstructs().clear();
		total = TaskManager.getInstance().initPublistTask(
				GlobalValue.getInstance().getPublisInstructs(), pageNo,
				PAGESIZE);
		if(GlobalValue.getInstance().getPublisInstructs()!=null)start = GlobalValue.getInstance().getPublisInstructs().size();
	}

	protected boolean isFirstInitData() {
		if (SystemParams.loadPublishInstruct == 0)
			return true;
		return false;
	}

	@Override
	public void setAdapterList() {
		super.setAdapterList();
		adapter.setList(GlobalValue.getInstance().getPublisInstructs());
		adapter.notifyDataSetChanged();
	}

	@Override
	protected void onSearchSuccess() {
		adapter.setList(GlobalValue.getInstance().getPublisInstructs());
		adapter.notifyDataSetChanged();

	}

	@Override
	protected void searchNextPageByCom() throws HttpException {
		pageNo++;
		total = TaskManager.getInstance().initPublistTask(
				GlobalValue.getInstance().getPublisInstructs(), pageNo,
				PAGESIZE);
		if(GlobalValue.getInstance().getPublisInstructs()!=null)start = GlobalValue.getInstance().getPublisInstructs().size();
	}
	
	public void doJob(){
		if(SystemParams.loadPublishInstruct==0){
			doLoadTask();
		}
		else{
			mRefreshListView.onRefreshComplete();
		}
	}


}
